package main

import (
	"fmt"
	"ginjt/controller"
	"ginjt/utils"
	"ginjt/validate"
	"git.yjqw.com/lmh/go-utils/did"
	"github.com/gin-gonic/gin"
	"github.com/gin-gonic/gin/binding"
	"github.com/go-playground/validator/v10"
	"github.com/gomodule/redigo/redis"
)

func main()  {
	con := utils.RedisClient.Get()
	defer con.Close()
	fmt.Println(con)
	//con.Do("SET","name","lmh")
	r,err:=con.Do("GET","name")
	if err != nil {
		fmt.Println(err.Error())
	}else {
		 v,_ := redis.String(r,err)
		 fmt.Println(v)
	}

}

func main1()  {

	did.InitDateCenter(1)

	rows,_ := utils.Db.Raw("select id,title from topic ").Rows()

	for rows.Next(){
		var id int
		var title string
		rows.Scan(&id,&title)
		fmt.Println(id,title)
	}

	 utils.Db.Close()



	router := gin.Default()

	//router.GET("/", func(c *gin.Context) {
	//	c.JSON(200,gin.H{"a":"b"})
	//})
	//
	//router.GET("/topic/:topic_id", func(c *gin.Context) {
	//	c.String(http.StatusOK,"ID=%s",c.Param("topic_id"))
	//})
	//
	//router.GET("/v1/topics", func(c *gin.Context) {
	//	username := c.Query("username")
	//	c.String(http.StatusOK,"ID=%s",username)
	//})

	if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
		v.RegisterValidation("aaaa", validate.CustomFunc)
	}

	controller.FileController(router,"/v1/file")

	controller.TopicController(router,"v1/topic")





	router.Run()

}
